<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="180px">
      <el-row>
        <el-col :span="24">
          <el-form-item label="会话数量限制" prop="cm">
            <el-input v-model="form.cm" placeholder="请输入会话数量限制" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="推荐功能阈值" prop="rt">
            <el-input v-model="form.rt" placeholder="请输入推荐功能阈值" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="缓冲页标语" prop="bt">
            <el-input
              v-model="form.bt"
              placeholder="请输入缓冲页标语"
              type="textarea"
              :rows="4"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="咨询页面引导语" prop="st">
            <el-input
              v-model="form.st"
              placeholder="请输入咨询页面引导语"
              type="textarea"
              :rows="4"
            />
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="文书撰写用户参考样例" prop="dw">
            <el-input
              v-model="form.dw"
              placeholder="请输入文书撰写用户参考样例"
              type="textarea"
              :rows="4"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="">
            <el-button type="primary" @click="submitForm">保 存</el-button>
            <!-- <el-button @click="cancel">重 置</el-button> -->
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { getAllConfig, upAllConfig } from "@/api/fzz";
export default {
  name: "Cache",
  data() {
    return {
      form: {},
      rules: {
        cm: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
        rt: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
        bt: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
        st: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
        dw: [{ required: true, message: "必填项不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    this.getConfig();
  },
  methods: {
    getConfig() {
      getAllConfig().then((response) => {
        console.log(response);
        this.form = { ...response.data };
      });
    },
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          upAllConfig({ ...this.form }).then((response) => {
            this.$modal.msgSuccess("修改成功");
          });
        }
      });
    },
    cancel() {
      this.resetForm("form");
      this.$modal.msgSuccess("重置成功");
    },
  },
};
</script>
